package com.ruoyi.project.channel.clientInfo.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.system.user.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.clientInfo.domain.ClientInfo;
import com.ruoyi.project.channel.clientInfo.service.IClientInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 客户端操作信息操作处理
 * 
 * @author zero
 * @date 2019-04-30
 */
@Controller
@RequestMapping("/channel/clientInfo")
public class ClientInfoController extends BaseController
{
    private String prefix = "channel/clientInfo";
	
	@Autowired
	private IClientInfoService clientInfoService;
	
	@RequiresPermissions("channel:clientInfo:view")
	@GetMapping()
	public String clientInfo()
	{
	    return prefix + "/clientInfo";
	}
	
	/**
	 * 查询客户端操作列表
	 */
	@RequiresPermissions("channel:clientInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ClientInfo clientInfo)
	{
		startPage();
		User user = getSysUser();
		String roleKey = ShiroUtils.getSysUser().getRoles().get(0).getRoleKey();
		List<ClientInfo> list = new ArrayList<ClientInfo>();
		clientInfo.setOrderStatus("1");
		if (roleKey.equals("channel")) {
			clientInfo.getParams().put("channelUserId", user.getUserId());
			list = clientInfoService.selectClientInfoList(clientInfo);
		} else if (roleKey.equals("admin") || roleKey.equals("admin2")) {
			list = clientInfoService.selectClientInfoList(clientInfo);
		}
		return getDataTable(list);
	}
	
	
	/**
	 * 导出客户端操作列表
	 */
	@RequiresPermissions("channel:clientInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClientInfo clientInfo)
    {
    	List<ClientInfo> list = clientInfoService.selectClientInfoList(clientInfo);
        ExcelUtil<ClientInfo> util = new ExcelUtil<ClientInfo>(ClientInfo.class);
        return util.exportExcel(list, "clientInfo");
    }
	
	/**
	 * 新增客户端操作
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存客户端操作
	 */
	@RequiresPermissions("channel:clientInfo:add")
	@Log(title = "客户端操作", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ClientInfo clientInfo)
	{		
		return toAjax(clientInfoService.insertClientInfo(clientInfo));
	}

	/**
	 * 修改客户端操作
	 */
	@GetMapping("/edit/{clientId}")
	public String edit(@PathVariable("clientId") String clientId, ModelMap mmap)
	{
		ClientInfo clientInfo = clientInfoService.selectClientInfoById(clientId);
		mmap.put("clientInfo", clientInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存客户端操作
	 */
	@RequiresPermissions("channel:clientInfo:edit")
	@Log(title = "客户端操作", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ClientInfo clientInfo)
	{		
		return toAjax(clientInfoService.updateClientInfo(clientInfo));
	}
	
	/**
	 * 删除客户端操作
	 */
	@RequiresPermissions("channel:clientInfo:remove")
	@Log(title = "客户端操作", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(clientInfoService.deleteClientInfoByIds(ids));
	}
	
}
